package com.elong.android.specialhouse.utils;

import android.content.Context;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.WindowManager;

import java.util.Arrays;

/**
 * @author kaiqi.li
 * @Description
 * @date 2015/11/19 18:04
 */
public class ImageTypeUtil {
    private static int[][] screenH_W  = {{1242,2208},{1080,1920},{800,1280},{766,1194},{480,800},{750,1334},{400,640}};
    private static int[] dalts = new int[screenH_W.length];
    public static int getImageSizeType(Context context) {
        DisplayMetrics dm = new DisplayMetrics();
        WindowManager wm = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE));
        wm.getDefaultDisplay().getMetrics(dm);
        int width = dm.widthPixels;
        int height = dm.heightPixels ;
        for (int i = 0; i < screenH_W.length; i++) {
            int daltX = screenH_W[i][0] - width;
            int daltY = screenH_W[i][1] = height;
            int dalt = ((int) Math.sqrt(daltX * daltX + daltY * daltY));
            dalts[i] = dalt ;
        }
        Log.i("ImageTypeUtil", Arrays.toString(dalts));
        return findIndexOfMin(dalts) + 1 ;
    }

    private static int findIndexOfMin(int[] arrays) {
        int index = 0 ;
        int min = arrays[index];

        for (int i = 0; i < arrays.length; i++) {
            if (min > arrays[i]) {
                min = arrays[i];
                index = i;
            }
        }
        return index;
    }
}
